package com.example.demo.controller;

import com.example.demo.mapper.MusicMapper;
import com.example.demo.pojo.Music;
import com.example.demo.util.DeleteFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class DeleteController {
    @Autowired
    MusicMapper musicMapper;

    @RequestMapping(value = "/music/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public Object delete(@PathVariable("id") Integer id){
        Map<Object,Object> map = new HashMap<>();
        System.out.println("Delete:"+id);
        DeleteFileUtil.deleteMusicFile(musicMapper.get(id));
        musicMapper.delete(id);
        map.put("code",0);
        return map;
    }
}
